1use std::error::Error as StdError;
4use std::fmt;
5
6pub type Result<T> = ::std::result::Result<T, Error>;
8
9#[derive(Debug)]
11pub enum Error {
12 SameAddress,
14 InvalidCode,
16 NoPatchArea,
18 NotExecutable,
20 NotInitialized,
22 AlreadyInitialized,
24 OutOfMemory,
26 UnsupportedInstruction,
28 RegionFailure(region::Error),
30}
31
32impl StdError for Error {
33 fn source(&self) -> Option<&(dyn StdError + 'static)> {
34 if let Error::RegionFailure(error) = self {
35 Some(error)
36 } else {
37 None
38 }
39 }
40}
41
42impl fmt::Display for Error {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 match self {
45 Error::SameAddress => write!(f, "Target and detour address is the same"),
46 Error::InvalidCode => write!(f, "Address contains invalid assembly"),
47 Error::NoPatchArea => write!(f, "Cannot find an inline patch area"),
48 Error::NotExecutable => write!(f, "Address is not executable"),
49 Error::NotInitialized => write!(f, "Detour is not initialized"),
50 Error::AlreadyInitialized => write!(f, "Detour is already initialized"),
51 Error::OutOfMemory => write!(f, "Cannot allocate memory"),
52 Error::UnsupportedInstruction => write!(f, "Address contains an unsupported instruction"),
53 Error::RegionFailure(ref error) => write!(f, "{}", error),
54 }
55 }
56}
57
58impl From<region::Error> for Error {
59 fn from(error: region::Error) -> Self {
60 Error::RegionFailure(error)
61 }
62}